package study.week05.config;

import lombok.RequiredArgsConstructor;


import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import study.week05.entity.Klass;
import study.week05.entity.School;
import study.week05.entity.Student;

import java.util.*;


@Configuration
@Import({DemoProperties.class})
@RequiredArgsConstructor
public class DemoAutoConfiguration{

    private final DemoProperties props;


    @Bean
    public Student student() {
        Student obj = new Student();
        Properties properties = props.getProps();
        obj.setAge(Integer.parseInt(properties.getProperty("student.age")));
        obj.setStudentName(properties.getProperty("student.name"));
        return obj;
    }

    @Bean
    public Klass klass() {
        Klass obj = new Klass();
        Properties properties = props.getProps();
        obj.setClassName((properties.getProperty("klass.name")));
        obj.setGrade(properties.getProperty("klass.grade"));
        return obj;
    }

    @Bean
    public School school() {
        School obj = new School();
        Properties properties = props.getProps();
        obj.setSchoolName((properties.getProperty("school.name")));
        obj.setAddress(properties.getProperty("school.address"));
        return obj;
    }

}
